//
//  RMMLandingedHeadView.m
//  Romomo
//
//  Created by puman on 2016/10/18.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMLandingedHeadView.h"

@implementation RMMLandingedHeadView
{
    UILabel *_userNameLabel;
    NSDictionary *_dic;
    UIImageView *_headImage;
    UILabel *_vLabel;
    UILabel *_sLabel;
}
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = kWhiteColor;
        UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, 100)];
        blackView.backgroundColor =[UIColor blackColor];
        [self addSubview:blackView];
        
        _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, blackView.bottom - 75 / 2, 75, 75)];
        _headImage.layer.masksToBounds = YES;
        _headImage.layer.cornerRadius = 75 / 2;
        _headImage.layer.borderWidth = 6;
        _headImage.layer.borderColor = kWhiteColor.CGColor;
        [self addSubview:_headImage];
        
        _userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_headImage.right + 12, _headImage.top, self.width -_headImage.right - 72, _headImage.height / 2)];
        _userNameLabel.textColor = COLORFROMCODE(0xFFFFFF, 1);
        _userNameLabel.font = kFont(16);
        [self addSubview:_userNameLabel];
        
        _setBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _setBut.frame = CGRectMake(self.width - 60, _userNameLabel.top, 60, _userNameLabel.height);
        [_setBut setTitle:@"设置" forState:(UIControlStateNormal)];
        [_setBut setTitleColor:COLORFROMCODE(0x53C7C6 , 1) forState:(UIControlStateNormal)];
        _setBut.titleLabel.font= kFont(16);
        [self addSubview:_setBut];
        
        _vLabel = [[UILabel alloc] initWithFrame:CGRectMake(_userNameLabel.left, _userNameLabel.bottom, 70, _userNameLabel.height)];
        _vLabel.font= kFont(14);
        _vLabel.textColor = COLORFROMCODE(0x2C2C2C, 1);
        [self addSubview:_vLabel];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(_vLabel.right + 3, _vLabel.top + 12, 2, _vLabel.height - 24)];
        label.backgroundColor = RGBA(240, 240, 240, 1);
        [self addSubview:label];
        
        _sLabel = [[UILabel alloc] initWithFrame:CGRectMake(label.right +kRow, _userNameLabel.bottom, self.width - label.right, _userNameLabel.height)];
        _sLabel.font= kFont(14);
        _sLabel.textColor = COLORFROMCODE(0x2C2C2C, 1);
        [self addSubview:_sLabel];

    }
    return self;
}
- (void)setDic:(NSDictionary *)dic{
    if ([dic allKeys].count) {
        [_headImage sd_setImageWithURL:[NSURL URLWithString:[RMMFileManager retrunObjWith:[NSString stringWithFormat:@"%@%@",kBaseUrl,dic[@"IMAGE_URL"]]]] placeholderImage:[UIImage imageNamed:@"Icon-iPhone-60@3x"]];
        _userNameLabel.text = [NSString stringWithFormat:@"您好, %@",dic[@"NAME"]];
        _vLabel.text = [NSString stringWithFormat:@"等级 %@",dic[@"LVL_NAME"]];
        _sLabel.text = [NSString stringWithFormat:@"颜值 %@分",dic[@"TOTAL_POINTS"]];

    } else {
        _headImage.image = [UIImage imageNamed:@"Icon-iPhone-60@3x"];
        _userNameLabel.text = @"您好, 容么么";
        _vLabel.text = @"等级 V0";
        _sLabel.text = @"颜值 0分";

    }
    [self changeLabelColorWith:_vLabel];
    [self changeLabelColorWith:_sLabel];
}
- (void)setYanZhiValue:(NSString *)yanZhiValue{
    _sLabel.text = [NSString stringWithFormat:@"颜值 %@分",yanZhiValue];
}
- (void)setLvValue:(NSString *)lvValue{
    _vLabel.text = [NSString stringWithFormat:@"等级 %@",lvValue];
}
- (void)changeLabelColorWith:(UILabel *)label{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    [attributedString addAttribute:NSForegroundColorAttributeName value:kBasicColor range:NSMakeRange(2, label.text.length - 2)];
    [label setAttributedText:attributedString];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
